package architecture.diagram.part;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.gmf.runtime.notation.View;

import architecture.Architecture;
import architecture.ArchitecturePackage;
import architecture.Feature;
import architecture.Module;
import architecture.Responsability;
import architecture.diagram.edit.parts.ArchitectureEditPart;
import architecture.diagram.edit.parts.FeatureEditPart;
import architecture.diagram.edit.parts.FeatureIsRealicedByEditPart;
import architecture.diagram.edit.parts.ModuleDependEditPart;
import architecture.diagram.edit.parts.ModuleEditPart;
import architecture.diagram.edit.parts.ModuleImplementEditPart;
import architecture.diagram.edit.parts.ResponsabilityEditPart;
import architecture.diagram.providers.ArchitectureElementTypes;

/**
 * @generated
 */
public class ArchitectureDiagramUpdater {

	/**
	 * @generated
	 */
	public static List<ArchitectureNodeDescriptor> getSemanticChildren(View view) {
		switch (ArchitectureVisualIDRegistry.getVisualID(view)) {
		case ArchitectureEditPart.VISUAL_ID:
			return getArchitecture_1000SemanticChildren(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureNodeDescriptor> getArchitecture_1000SemanticChildren(
			View view) {
		if (!view.isSetElement()) {
			return Collections.emptyList();
		}
		Architecture modelElement = (Architecture) view.getElement();
		LinkedList<ArchitectureNodeDescriptor> result = new LinkedList<ArchitectureNodeDescriptor>();
		for (Iterator<?> it = modelElement.getHasModules().iterator(); it
				.hasNext();) {
			Module childElement = (Module) it.next();
			int visualID = ArchitectureVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == ModuleEditPart.VISUAL_ID) {
				result.add(new ArchitectureNodeDescriptor(childElement,
						visualID));
				continue;
			}
		}
		for (Iterator<?> it = modelElement.getHasResponsabilities().iterator(); it
				.hasNext();) {
			Responsability childElement = (Responsability) it.next();
			int visualID = ArchitectureVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == ResponsabilityEditPart.VISUAL_ID) {
				result.add(new ArchitectureNodeDescriptor(childElement,
						visualID));
				continue;
			}
		}
		for (Iterator<?> it = modelElement.getHasFeatures().iterator(); it
				.hasNext();) {
			Feature childElement = (Feature) it.next();
			int visualID = ArchitectureVisualIDRegistry.getNodeVisualID(view,
					childElement);
			if (visualID == FeatureEditPart.VISUAL_ID) {
				result.add(new ArchitectureNodeDescriptor(childElement,
						visualID));
				continue;
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getContainedLinks(View view) {
		switch (ArchitectureVisualIDRegistry.getVisualID(view)) {
		case ArchitectureEditPart.VISUAL_ID:
			return getArchitecture_1000ContainedLinks(view);
		case ModuleEditPart.VISUAL_ID:
			return getModule_2001ContainedLinks(view);
		case ResponsabilityEditPart.VISUAL_ID:
			return getResponsability_2002ContainedLinks(view);
		case FeatureEditPart.VISUAL_ID:
			return getFeature_2003ContainedLinks(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getIncomingLinks(View view) {
		switch (ArchitectureVisualIDRegistry.getVisualID(view)) {
		case ModuleEditPart.VISUAL_ID:
			return getModule_2001IncomingLinks(view);
		case ResponsabilityEditPart.VISUAL_ID:
			return getResponsability_2002IncomingLinks(view);
		case FeatureEditPart.VISUAL_ID:
			return getFeature_2003IncomingLinks(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getOutgoingLinks(View view) {
		switch (ArchitectureVisualIDRegistry.getVisualID(view)) {
		case ModuleEditPart.VISUAL_ID:
			return getModule_2001OutgoingLinks(view);
		case ResponsabilityEditPart.VISUAL_ID:
			return getResponsability_2002OutgoingLinks(view);
		case FeatureEditPart.VISUAL_ID:
			return getFeature_2003OutgoingLinks(view);
		}
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getArchitecture_1000ContainedLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getModule_2001ContainedLinks(
			View view) {
		Module modelElement = (Module) view.getElement();
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		result.addAll(getOutgoingFeatureModelFacetLinks_Module_Depend_4002(modelElement));
		result.addAll(getOutgoingFeatureModelFacetLinks_Module_Implement_4003(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getResponsability_2002ContainedLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getFeature_2003ContainedLinks(
			View view) {
		Feature modelElement = (Feature) view.getElement();
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		result.addAll(getOutgoingFeatureModelFacetLinks_Feature_IsRealicedBy_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getModule_2001IncomingLinks(
			View view) {
		Module modelElement = (Module) view.getElement();
		Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences = EcoreUtil.CrossReferencer
				.find(view.eResource().getResourceSet().getResources());
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		result.addAll(getIncomingFeatureModelFacetLinks_Feature_IsRealicedBy_4001(
				modelElement, crossReferences));
		result.addAll(getIncomingFeatureModelFacetLinks_Module_Depend_4002(
				modelElement, crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getResponsability_2002IncomingLinks(
			View view) {
		Responsability modelElement = (Responsability) view.getElement();
		Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences = EcoreUtil.CrossReferencer
				.find(view.eResource().getResourceSet().getResources());
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		result.addAll(getIncomingFeatureModelFacetLinks_Module_Implement_4003(
				modelElement, crossReferences));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getFeature_2003IncomingLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getModule_2001OutgoingLinks(
			View view) {
		Module modelElement = (Module) view.getElement();
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		result.addAll(getOutgoingFeatureModelFacetLinks_Module_Depend_4002(modelElement));
		result.addAll(getOutgoingFeatureModelFacetLinks_Module_Implement_4003(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getResponsability_2002OutgoingLinks(
			View view) {
		return Collections.emptyList();
	}

	/**
	 * @generated
	 */
	public static List<ArchitectureLinkDescriptor> getFeature_2003OutgoingLinks(
			View view) {
		Feature modelElement = (Feature) view.getElement();
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		result.addAll(getOutgoingFeatureModelFacetLinks_Feature_IsRealicedBy_4001(modelElement));
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<ArchitectureLinkDescriptor> getIncomingFeatureModelFacetLinks_Feature_IsRealicedBy_4001(
			Module target,
			Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences) {
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		Collection<EStructuralFeature.Setting> settings = crossReferences
				.get(target);
		for (EStructuralFeature.Setting setting : settings) {
			if (setting.getEStructuralFeature() == ArchitecturePackage.eINSTANCE
					.getFeature_IsRealicedBy()) {
				result.add(new ArchitectureLinkDescriptor(setting.getEObject(),
						target,
						ArchitectureElementTypes.FeatureIsRealicedBy_4001,
						FeatureIsRealicedByEditPart.VISUAL_ID));
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<ArchitectureLinkDescriptor> getIncomingFeatureModelFacetLinks_Module_Depend_4002(
			Module target,
			Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences) {
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		Collection<EStructuralFeature.Setting> settings = crossReferences
				.get(target);
		for (EStructuralFeature.Setting setting : settings) {
			if (setting.getEStructuralFeature() == ArchitecturePackage.eINSTANCE
					.getModule_Depend()) {
				result.add(new ArchitectureLinkDescriptor(setting.getEObject(),
						target, ArchitectureElementTypes.ModuleDepend_4002,
						ModuleDependEditPart.VISUAL_ID));
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<ArchitectureLinkDescriptor> getIncomingFeatureModelFacetLinks_Module_Implement_4003(
			Responsability target,
			Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences) {
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		Collection<EStructuralFeature.Setting> settings = crossReferences
				.get(target);
		for (EStructuralFeature.Setting setting : settings) {
			if (setting.getEStructuralFeature() == ArchitecturePackage.eINSTANCE
					.getModule_Implement()) {
				result.add(new ArchitectureLinkDescriptor(setting.getEObject(),
						target, ArchitectureElementTypes.ModuleImplement_4003,
						ModuleImplementEditPart.VISUAL_ID));
			}
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<ArchitectureLinkDescriptor> getOutgoingFeatureModelFacetLinks_Feature_IsRealicedBy_4001(
			Feature source) {
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		for (Iterator<?> destinations = source.getIsRealicedBy().iterator(); destinations
				.hasNext();) {
			Module destination = (Module) destinations.next();
			result.add(new ArchitectureLinkDescriptor(source, destination,
					ArchitectureElementTypes.FeatureIsRealicedBy_4001,
					FeatureIsRealicedByEditPart.VISUAL_ID));
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<ArchitectureLinkDescriptor> getOutgoingFeatureModelFacetLinks_Module_Depend_4002(
			Module source) {
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		for (Iterator<?> destinations = source.getDepend().iterator(); destinations
				.hasNext();) {
			Module destination = (Module) destinations.next();
			result.add(new ArchitectureLinkDescriptor(source, destination,
					ArchitectureElementTypes.ModuleDepend_4002,
					ModuleDependEditPart.VISUAL_ID));
		}
		return result;
	}

	/**
	 * @generated
	 */
	private static Collection<ArchitectureLinkDescriptor> getOutgoingFeatureModelFacetLinks_Module_Implement_4003(
			Module source) {
		LinkedList<ArchitectureLinkDescriptor> result = new LinkedList<ArchitectureLinkDescriptor>();
		for (Iterator<?> destinations = source.getImplement().iterator(); destinations
				.hasNext();) {
			Responsability destination = (Responsability) destinations.next();
			result.add(new ArchitectureLinkDescriptor(source, destination,
					ArchitectureElementTypes.ModuleImplement_4003,
					ModuleImplementEditPart.VISUAL_ID));
		}
		return result;
	}

}
